package com.xdf.advice;

import com.xdf.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理
 * @author chanchaw
 * @create 2025-08-15 15:57
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {
    @ExceptionHandler(value = Exception.class)
    public CommonResponse<String> handleSysException(HttpServletRequest req, Exception ex){
        CommonResponse<String> res = new CommonResponse<>(-1,ex.getMessage());
        log.error("系统出现异常：[{}]", ex.getMessage(),ex.toString());
        return res;
    }
}
